package com.suypower.carManage.action;

import javax.servlet.ServletException;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

public class MilageAction extends ActionSupport {

	private String id;
	private String car_code;
	private String driver;
	private String time;
	private String milage;
	private String remark;

	public String getCar_code() {
		return car_code;
	}

	public void setCar_code(String carCode) {
		car_code = carCode;
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getMilage() {
		return milage;
	}

	public void setMilage(String milage) {
		this.milage = milage;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String execute() {
		String res = "";
		DAO dao = new DAO();
		String sql="";
		if(id==null||id.equals("")){
			sql = "INSERT INTO tb_milage(car_code,driver,time,milage,remark)VALUES('"
				+ car_code
				+ "','"
				+ driver
				+ "','"
				+ time
				+ "','"
				+ milage
				+ "','" + remark + "')";
		}else{
			sql="UPDATE tb_milage  SET car_code='"+car_code+"' ,driver='"+driver+"' ,time='"+time+"' ,milage='"+milage+"' ,remark='"+remark+"' WHERE id="+id;
		}
		
		int count=0;
		try {
			count=dao.execCommand(ConstUtil.DBNAME, sql);
			if(count>0){
				res=this.SUCCESS;
			}else{
				res=this.ERROR;
			}
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return res;
	}
}
